<?php
session_start();
include_once 'classes/DBCon.php';
include_once 'classes/Forum.php'
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Railway Official Website</title>
        <link rel="stylesheet" href="css/foundation.css"/>
        <link rel="stylesheet" href="css/normalize.css"/>
        <link rel="stylesheet" href="css/jquery-ui.css" />
        <script src="js/vendor/jquery.js"></script>
        <script src="js/ui/jquery-ui.js"></script>
        <script src="js/vendor/custom.modernizr.js"></script>
        <script src="js/forum.js"></script>
        <style type="text/css" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
		#wrap {display:table;height:100%}
        fieldset { border:2px solid grey }
        legend {
              padding: 0.2em 0.5em;
              border:2px solid white;
              color:black;
              font-size:150%;
              text-align:left;
        }
	</style>
        


    </head>
    <body bgcolor="transparent">
        <div>
            <nav class="top-bar">
                <ul class="title-area">
                    <li class="name" onClick="void(0);">
                        <h1><a href="ForumMain.php">Railway Community Forum</a></h1>
                    </li>
                    <li class="divider"></li>
                    <li class="toggle-topbar menu-icon">
                        <a href="#"><span>menu</span></a>
                    </li>
                </ul>
                <section class="top-bar-section">
                    <ul class="right">
                        <li class="divider"></li>
                        <li><a href="index.php">Home</a></li>
                        <li class="divider"></li>
                        <?php
                        if (isset($_SESSION['username'])) {
                            echo '<li><a href="profile.php">Welcome, ' . $_SESSION['username'] . '!</a></li>';
                            echo '<li class="divider"></li>';
                            echo '<li><a href="logout.php">Logout</a></li>';
                            echo '<li class="divider"></li>';
                        }
                        else{
                            echo '<li><a href="loginPage.php">Login</a></li>';
                            echo '<li class="divider"></li>';
                            echo '<li><a href="register.php">Register</a></li>';
                            echo '<li class=divider"></li>';
                        }
                        ?>
                    </ul>
                </section>
            </nav>
        </div>
        <?php
         $forum = new Forum();
         $forum->displayCreateThread();
        ?>
        
        <script type="text/javascript">
        $(document).ready(function(){
        var left = 500;
        $('#charcounter').text('Characters left: ' + left);

            $('#comment').keyup(function () {

            left = 500 - $(this).val().length;

            if(left < 0){
                $('#charcounter').addClass("overlimit");
            }
            if(left >= 0){
                $('#charcounter span').removeClass("overlimit");
            }

            $('#charcounter').text('Characters left: ' + left);
    });
    });
    
    function addNewThread() {
                var comments2 = document.getElementById('comment').value;
                var title = document.getElementById('title').value;
                if(comments2.length==0 || title.length==0){
                    $('#comment').addClass('error');
                    $('#commentErr').text("Required Field").show();
                    $('#title').addClass('error');
                    $('#titleErr').text("Required Field").show();
                }else{
                    alert('b');
                    $.ajax({
                    type: 'POST',
                    url: 'action.php',
                    data: $('#newthreadform').serialize(),
                    success: function(result) {
                        if (!result.error) {
                            $('#commentErr').fadeIn('fast').addClass('success').removeClass('alert').html(result.message).delay(4000).fadeOut('slow');    
                            location.replace('view_threads.php?permalink='+result.threadid);
                        } else {
                            $('#commentErr').fadeIn('slow').addClass('alert').removeClass('success').html(result.message).delay(4000).fadeOut('slow');
                        }
                            
                        }
                    });
                }
                }
        </script>
    </body>
</html>
